package com.kyzh.core.activities

import android.graphics.Color
import android.os.Bundle
import android.view.View
import android.view.WindowManager
import androidx.viewpager.widget.ViewPager
import com.gushenge.core.base.activity.BaseActivity
import com.gushenge.core.dao.MMKVConsts.ifUse
import com.kyzh.core.R
import com.kyzh.core.adapters.LaunchAdapter
import com.kyzh.core.pager.home.MainActivity
import com.kyzh.core.utils.startActivity
import kotlinx.android.synthetic.main.act_guide.*

class GuideActivity : BaseActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.act_guide)
        val window = window
        val decorView = window.decorView
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                or WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
        decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR)
        /*if (Build.VERSION.SDK_INT>= Build.VERSION_CODES.R) {
            decorView.windowInsetsController?.hide(WindowInsets.Type.statusBars())
            decorView.windowInsetsController?.hide(WindowInsets.Type.navigationBars())
        }else{
        }*/

        window.statusBarColor = Color.TRANSPARENT
        //设置底部导航栏颜色
        window.navigationBarColor = Color.TRANSPARENT
        launchAct()
        now_in.setOnClickListener {
            ifUse = 1
            startActivity<MainActivity>()
            finish()
        }
    }

    /*启动页*/
    private fun launchAct() {
        main_viewpager.adapter = LaunchAdapter(this@GuideActivity)
        main_viewpager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {

            }

            override fun onPageSelected(position: Int) {
                if (position == 2) {
                    now_in.visibility = View.VISIBLE
                } else {
                    now_in.visibility = View.GONE
                }
            }

            override fun onPageScrollStateChanged(state: Int) {

            }
        })
    }
}
